package com.xxxx.aop.around;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.context.annotation.Configuration;

import java.lang.reflect.Method;


@Aspect
@Configuration
public class AroundAdvice {

   @Around("com.xxxx.aop.PointCut.AroundController()")
    public Object AroundAdvice(ProceedingJoinPoint joinPoint){
       Object proceed = null;
       try {
           //第一种方法：获取到反射类 然后根据反射的方法执行重定向方法
           Object[] args = joinPoint.getArgs();
           Class declaringType = joinPoint.getSignature().getDeclaringType();
           Method aroundTest = declaringType.getDeclaredMethod("aroundTestTwo",String.class,String.class);
           Object aThis = joinPoint.getThis();//如果使用此对象  则会陷入死循环
           Object invoke = aroundTest.invoke(declaringType.newInstance(), args[0], args[1]);
           System.out.println(invoke);

           //第二种方法：直接利用ProceedingJoinPoint的proceed方法执行目标方法
           proceed = joinPoint.proceed(args);

       } catch (Throwable throwable) {
           throwable.printStackTrace();
       }

        return proceed;

    }



}
